package com.testnacos.config;



import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import org.springframework.stereotype.Component;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.core.annotation.Order;
@Component
//使用缓存则过滤器
@WebFilter(urlPatterns = "/*",asyncSupported = true)
public class HystrixRequestFilter  implements Filter {

    public void destroy() {
    }



    public void init(FilterConfig config) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HystrixRequestContext hystrixRequestContext=
                HystrixRequestContext.initializeContext();//开启
        try{
            filterChain.doFilter(servletRequest, servletResponse);
        }finally {
            hystrixRequestContext.close();//关闭
        }

    }


}
